#ifndef CUBE_H_
#define CUBE_H_


#include "main.h"

#include <string>
#include <sstream>

using namespace std;

enum RUBIK_SIDES {
	TOP=0, BOTTOM, LEFT, RIGHT, FORWARD, BACKWARD, MIDDLE_X, MIDDLE_Y, MIDDLE_Z, NONE
};

enum FACE_SIDE {
	T=0, D, L, R, F, B
};

enum RUBIK_ROTATE {
	CW=0, CCW, NONE_R
};

struct C_Face {
    vector<vec3> vi;
	vec3 color;
	int id;
	
    C_Face() { vi.reserve(4);}

	void addVertex(vec3 v) {
        vi.push_back(v);
    }

	void drawFace () {
		glColor3f(color[0], color[1], color[2]);
		glEnable (GL_BLEND);
		glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glBegin (GL_QUADS);
			for (int i=0; i<vi.size(); i++) {
				glVertex3f(vi[i][0],vi[i][1],vi[i][2]);
			}
		glEnd();
		glColor3f(1,1,1);
	}

	static void swapLoc (C_Face *f1, C_Face *f2) {
		vector <vec3> tempv;
		tempv.reserve(4);
		tempv=f1->vi;
		f1->vi=f2->vi;
		f2->vi=tempv;
	}

	void drawFlatFace(vec2 topleft, float width, float height){
		
		float ws = 2*1.25;
		float w = float(glutGet(GLUT_WINDOW_WIDTH));
		float h = float(glutGet(GLUT_WINDOW_HEIGHT));

		
		w = min(w,h);
		h = w;

		glColor3f(0,0,0);
		glEnable (GL_LINE_STIPPLE);
		glLineWidth(3.90);
		glBegin(GL_LINE_LOOP);
				glVertex2f(ws*topleft[0]/w,ws*topleft[1]/h);
				glVertex2f(ws*(topleft[0]+width)/w,ws*topleft[1]/h);
				glVertex2f(ws*(topleft[0]+width)/w,ws*(topleft[1]-height)/h);
				glVertex2f(ws*topleft[0]/w,ws*(topleft[1]-height)/h);
		glEnd();

		glColor3f(color[0],color[1],color[2]);
				
		glBegin(GL_QUADS);
			    glVertex2f(ws*topleft[0]/w,ws*topleft[1]/h);
				glVertex2f(ws*(topleft[0]+width)/w,ws*topleft[1]/h);
				glVertex2f(ws*(topleft[0]+width)/w,ws*(topleft[1]-height)/h);
				glVertex2f(ws*topleft[0]/w,ws*(topleft[1]-height)/h);	
		glEnd();
		glColor3f(1,1,1);
	
		
	}
};

const double AFC=.14;

class cube {

public:
	cube(vec3 c);
	void drawCube();
	inline void setX(int x) {deg_x=((deg_x+x) % 360);}
	inline void setY(int y) {deg_y=(deg_y+y)%360;}
	inline void setZ(int z) {deg_z=(deg_z+z)%360;}

	inline void resetX() {deg_x=0;}
	inline void resetY() {deg_y=0;}
	inline void resetZ() {deg_z=0;}
	inline void resetAll() {resetX(); resetY(); resetZ();}

	bool location[9];
	C_Face * myFaces[6];

private:

	int deg_x;
	int deg_y;
	int deg_z;
	vec3 center;
};

#endif